package 课程设计报告_hb_7_5;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

import org.junit.Test;

/**
 * @author Jiang Zhiyan
 *
 * 2021年7月5日 下午3:22:22
 *
 */
public class FileInputStreamTest {
     
	@Test
	public void readFile() throws Exception {
		try(FileInputStream fis = new FileInputStream("./demo/d03.txt");){
			byte[] buff = new byte[0];
			byte data =-1;
			while((data= (byte)fis.read())!=-1) {
				buff = Arrays.copyOf(buff, buff.length+1);
				buff[buff.length-1]= data;
			}
			System.out.println(Arrays.toString(buff));
			System.out.println(buff.length);
			String str = new String(buff);
			System.out.println(str);
		}
	}
	
	@Test
	public void readFile2() throws Exception{
		try(FileInputStream fis = new FileInputStream("./demo/d03.txt");){
			File f =new File("./demo/d03.txt");
			System.out.println(f.length());
			byte[] buff = new byte[(int) f.length()];
			int count = fis.read(buff);
			System.out.println(Arrays.toString(buff));
			System.out.println(count);
			String str= new String (buff);
			System.out.println(str);
					}
	}
}
